package com.itcast.dao;

import com.itcast.pojo.Menu;
import com.itcast.pojo.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

public interface RoleDao {
    @Select("select r.* from health.t_role r , health.t_user_role ur where r.id = role_id and ur.user_id = #{userId}")
    Set<Role> findByUserId(@Param("userId") int userId);
    @Select("select r.* FROM t_role r,t_role_menu rm where rm.role_id=r.id and rm.menu_id=#{menuId}")
    Set<Role> findByMenuId(@Param("menuId")Integer menuId);
    @Select("select * from t_role")
    List<Role> findAll();
    @Insert("insert into t_user_role values(#{userId},#{roleId})")
    void addUserIdAndRoleId(@Param("userId") int userId,@Param("roleId")int roleId);
    @Delete("delete from t_user_role where user_id = #{userId}")
    void delUserAndRoleByUserId(@Param("userId") int userId);



}
